// TCPClient project main.go
package main

import (
    "fmt"
    "net"
    "os"
)

func main() {
    var buf [512]byte
    service := "192.168.251.170:7007"
    //udpAddr, err := net.ResolveUDPAddr("udp4", service)
    tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
    checkErr(err)
    conn, err := net.DialTCP("tcp", nil, tcpAddr)
    defer conn.Close()
    checkErr(err)
    conn.RemoteAddr()
    n, err := conn.Write([]byte("Hello server!"))
    checkErr(err)
    for true  {
	    n, err = conn.Read(buf[0:])
	    checkErr(err)
	    fmt.Println("Reply from server ", string(buf[0:n]))
    }
    os.Exit(0)
}

func checkErr(err error) {
    if err != nil {
        fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
        os.Exit(1)
    }
}